package chapter_09_composite.typical;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by CharloYao on 2017/3/6.
 */
public class CompositeCompany extends Company {

    private List<Company> children = new ArrayList<>();

    public CompositeCompany(String name) {
        super(name);
    }

    @Override
    protected void add(Company company) {
        children.add(company);
    }

    @Override
    protected void remove(Company company) {
        children.add(company);
    }

    @Override
    protected void display(int depth) {
        StringBuilder sb = new StringBuilder();
        for(int i=1;i<=depth;i++){
            sb.append("-");
        }
        System.out.println(new String(sb) + this.getName());
        for(Company company : children){
            company.display(depth + 2);
        }
    }
}
